package com.example.myapplication.slice;

import com.example.myapplication.ResourceTable;
import com.example.myapplication.ability.MainAbility;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;

public class SplashAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_splash);
        findComponentById(ResourceTable.Id_btn_to_login).setClickedListener(this);
        findComponentById(ResourceTable.Id_btn_to_main).setClickedListener(this);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_btn_to_login:
                present(new LoginAbilitySlice(), new Intent());
                break;
            case ResourceTable.Id_btn_to_main:
                Operation operation = new Intent.OperationBuilder()
                        .withBundleName("com.example.myapplication")
                        .withAbilityName(MainAbility.class.getCanonicalName())
                        .build();
                Intent intent = new Intent();
                intent.setOperation(operation);
                startAbility(intent);
                break;
            default:
                break;
        }
    }
}
